library(tidyverse)
library(plotly)
library(p8105.datasets)
data("nyc_airbnb")

nyc_airbnb = 
  nyc_airbnb %>% 
  mutate(
    rating = review_scores_location /2
  ) %>% 
  select(
    neighbourhood_group, neighbourhood, rating, price, room_type, lat, long
  ) %>% 
  filter(
    neighbourhood_group == "Manhattan",
    room_type == "Entire home/apt",
    price <= 500,
    price >= 100
  )

let’s make a scatterplot - but interactive… note: type = "scatter", mode = "markers" aka a scatterplot note: "\nRating: ", rating = that backslash + n allows you to name a new line for your label

nyc_airbnb %>% 
  mutate(
    label = str_c("Price: $", price, "\nRating: ", rating)
  ) %>% 
  plot_ly(
    x = ~lat, y = ~long, color = ~price,
    text = ~label, 
    type = "scatter", mode = "markers", alpha = 0.5
  )

lets make a box plot - but interactive…

nyc_airbnb %>%
  mutate(
    neighbourhood = fct_reorder(neighbourhood, price)
  ) %>% 
  plot_ly(
    x = ~neighbourhood, y = ~price, color = ~neighbourhood,
    type = "box", colors = ~"viridis"
  )

maybe barcharts next?

nyc_airbnb %>% 
  count(neighbourhood) %>% 
  mutate(
    neighbourhood = fct_reorder(neighbourhood, n)
  ) %>% 
  plot_ly(
    x = ~neighbourhood, y = ~n,
    type = "bar"
  )